package api

import (
	"github.com/gin-gonic/gin"
	"github.com/nntaoli-project/goex"
	"net/http"
	"quantization_trading/src/models"
	"quantization_trading/src/server"
	"quantization_trading/src/util"
	"strings"
)



func AddPrice(c *gin.Context)  {
	var data models.Price
	c.ShouldBindJSON(&data)
	if data.ContractType == ""{
		data.ContractType = goex.SWAP_USDT_CONTRACT
	}
	data.Symbol = strings.ToLower(data.Symbol)
	data.Exchange = strings.ToLower(data.Exchange)
	code := server.AddPrice(data)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

func DelPrice(c *gin.Context)  {
	var data models.Price
	c.ShouldBindJSON(&data)
	if data.ContractType == ""{
		data.ContractType = goex.SWAP_USDT_CONTRACT
	}
	data.Symbol = strings.ToLower(data.Symbol)
	data.Exchange = strings.ToLower(data.Exchange)
	code := server.UnSubPrice(data)
	c.JSON(http.StatusOK,gin.H{
		"status":  code,
		"message": util.GetErrMsg(code),
	})
}

func FindAllPrice(c *gin.Context)  {
	price_list, err := models.FindAllPrice()
	if err !=nil{
		c.JSON(http.StatusOK,gin.H{
			"status":  util.ERROR,
			"message": util.GetErrMsg(util.FUND_ERROR),
		})
	}else {
		c.JSON(http.StatusOK,gin.H{
			"status":  util.SUCCESS,
			"message": price_list,
		})
	}
}